/*
 * BankAccountTests.java
 *
 *  
 */
package org.msb.finance.data;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import java.math.BigDecimal;

import org.junit.Before;
import org.junit.Test;

/**
 * 
 * 
 * @author Marc Boudreau
 * 
 */
@SuppressWarnings("nls")
public class BankAccountTests {

	/*
	 * 
	 */
	private BankAccount account;

	/**
	 * @throws Exception
	 */
	@Before
	public void setUp() throws Exception {
		account = new BankAccount("Test Bank Account");
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testGetDefaultMinimumDesiredBalance() throws Exception {
		assertNotNull(account.getMinimumDesiredBalance());
		assertEquals(new BigDecimal(0), account.getMinimumDesiredBalance());
	}

	/**
	 * Test method for {@link BankAccount#setMinimumDesirableBalance(BigDecimal)}.
	 */
	@Test
	public void testSetMinimumDesiredBalance() {
		final BigDecimal BALANCE = new BigDecimal(45.6f);
		account.setMinimumDesirableBalance(BALANCE);

		assertEquals(BALANCE, account.getMinimumDesiredBalance());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetNegativeMinimumDesiredBalance() throws Exception {
		final BigDecimal BALANCE = new BigDecimal(-500);
		account.setMinimumDesirableBalance(BALANCE);

		assertEquals(BALANCE, account.getMinimumDesiredBalance());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetZeroMinimumDesiredBalance() throws Exception {
		final BigDecimal BALANCE = new BigDecimal(0);
		account.setMinimumDesirableBalance(BALANCE);

		assertEquals(BALANCE, account.getMinimumDesiredBalance());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetMinimumDesiredBalanceToNull() throws Exception {
		try {
			account.setMinimumDesirableBalance(null);
			fail("Expected a NullPointerException to be thrown.");
		} catch (NullPointerException ex) {
			// Pass.
		}
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testGetDefaultOverdraftLimit() throws Exception {
		assertNotNull(account.getOverdraftLimit());
		assertEquals(new BigDecimal(0), account.getOverdraftLimit());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetOverdraftLimit() throws Exception {
		final BigDecimal LIMIT = new BigDecimal(500);
		account.setOverdraftLimit(LIMIT);

		assertEquals(LIMIT, account.getOverdraftLimit());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetOverdraftLimitNegative() throws Exception {
		final BigDecimal LIMIT = new BigDecimal(-1000);
		try {
			account.setOverdraftLimit(LIMIT);
			fail("Expected an IllegalArgumentException to be thrown.");
		} catch (IllegalArgumentException ex) {
			// Pass.
		}
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetOverdraftLimitToNull() throws Exception {
		try {
			account.setOverdraftLimit(null);
			fail("Expected an NullPointerException to be thrown.");
		} catch (NullPointerException ex) {
			// Pass.
		}
	}
}
